#ifndef __LEARNDX_SCOLORF_H_INCLUDE__
#define __LEARNDX_SCOLORF_H_INCLUDE__
#include "LDXConfig.h"


namespace ldx
{
	namespace render
	{
		class SColorf;

		SColorf U32ToSColorf(uint color);

		//range [0,1]
		class SColorf
		{
		public:
			SColorf() {}

			SColorf(float R, float G, float B, float A)
				:R(R),G(G),B(B),A(A)
			{

			}

			SColorf(uint value)
			{

			}

			void operator=(uint value)
			{

			}

			float getRed()const
			{
				return R;
			}

			float getGreen()const
			{
				return G;
			}

			float getBlue()const
			{
				return B;
			}

			float getAlpha()const
			{
				return A;
			}

			void setRed(float R)
			{
				this->R = R;
			}

			void setGreen(float G)
			{
				this->G = G;
			}

			void setBlue(float B)
			{
				this->B = B;
			}

			void setAlpha()
			{
				this->A = A;
			}

			float& operator[](int index)
			{
				return *(Data+index);
			}

			const float* getData()
			{
				return Data;
			}

			bool operator==(const SColorf& other)const
			{
				for (int i = 0; i < 4; ++i)
				{
					if (!mt::equals(Data[i], other.Data[i], mt::ROUNDING_ERROR_f32))
						return false;
				}
				return true;
			}

			bool operator!=(const SColorf& other)const
			{
				return !(*this == other);
			}


			bool operator<(const SColorf& other)const
			{
				for (int i = 0; i < 4; ++i)
				{
					if (Data[i]>=other.Data[i])
						return false;
				}
				return true;
			}


			SColorf getInterpolated(const SColorf &other, float d) const
			{
				d = mt::clamp(d, 0.f, 1.f);
				const float inv = 1.0f - d;
				return SColorf(other.getAlpha()*inv + getAlpha()*d,
					other.getRed()*inv + getRed()*d,
					other.getGreen()*inv + getGreen()*d,
					other.getBlue()*inv + getBlue()*d);
			}
			
			union
			{
				struct { float R, G, B, A; };
				struct { float Data[4]; };
			};
		};

		inline SColorf U32ToSColorf(uint color)
		{
			SColorf c;
			mt::uint R = (color & 0xff000000) >> 24;
			mt::uint G = (color & 0x00ff0000) >> 16;
			mt::uint B = (color & 0x0000ff00) >> 8;
			mt::uint A = (color & 0x000000ff);
			c.R = ((float)((float)R / 255.0f));
			c.G = ((float)((float)G / 255.0f));
			c.B = ((float)((float)B / 255.0f));
			c.A = ((float)((float)A / 255.0f));
			return c;
		}
	}
}

#endif//! __LEARNDX_SCOLOR_H_INCLUDE__